##  ITEM RESPONSE THEORY: PROPOSED GUESSING MODEL
##  MODEL FOR MEASURMENT OF POLITICAL KNOWLEDGE

model {
	# LOOP OVER N RESPONDENTS
	for (i in 1:N) {        
		# LOOP OVER K ITEMS
	    for (k in 1:K) {    
	    	# LOGISTIC MODEL FOR POLITICAL KNOWLEDGE
	    	y[i,k] ~ dbern (p[i,k])
	    	logit(p.ability[i,k]) <- beta[k]*(theta[i] - alpha[k])
	    	
	    	# GUESSING FUNCTION
	    	guess.star[i,k] <- exp(b[k]*(theta[i] - alpha[k]))/(1 + (M-1)*exp(b[k]*(theta[i] - alpha[k])))   	
	    	guess[i,k] <- guess.ind[k]*guess.star[i,k] # INDICATOR FOR GUESS ITEMS
	    	
	    	# PROBABILITY OF SUCCESS	
	    	p[i,k] <- p.ability[i,k] + (1 - p.ability[i,k])*guess[i,k]
	    }    
	    # DISTRIBUTIONAL ASSUMPTION FOR THE LATENT TRAIT
	    theta[i] ~ dnorm (0, 1)
    }    
             
	# DISTRIBUTIONS OF ITEM PARAMETERS
    for (k in 1:K) {
    	beta[k] ~ dnorm (1, 0.5) T(0,)  # DISCRIMINATION PARAMETER; USUALLY [0.5, 3]
    	alpha[k] ~ dnorm (0, tau.alpha)  # DIFFICULTY PARAMETER
    	b.star[k] ~ dunif (0, 1)
    	b[k] <- guess.ind[k]*b.star[k]
    }   

	tau.alpha ~ dgamma (0.01, 0.01) # shape and rate;
	sigma.alpha <- 1/sqrt(tau.alpha)

} # END OF MODEL


